
const replaceStart = function(v,isShow){
    if(isShow){
        return v
    }else{
        return v.replace(/(\d{3})\d{5}(\d{3})/,"$1*****$2") 
    }
}
const formatDate = function(date,dateTemp="yyyy-MM-dd HH:mm:ss"){
    let tempDate = new Date(date);
    if( tempDate == "Invalid Date" ){
        return date;
    }
    let dateMap = {
        y : String(tempDate.getFullYear()),
        M : String(tempDate.getMonth() + 1),
        d : String(tempDate.getDate()),
        H : String(tempDate.getHours()),
        m : String(tempDate.getMinutes()),
        s : String(tempDate.getSeconds())
    }

    let reg = /y+|M+|d+|H+|m+|s+/g;
    let dateStr = dateTemp.replace(reg,function(match){
        let k = match[0];
        let t = dateMap[k];
        return t.padStart(match.length,"0")
    })
    return dateStr;
}

let myfilter = {
    replaceStart,
    formatDate
}
export default {
    ...myfilter,
    install(Vue){
        Vue.filter("replaceStart",replaceStart);
        Vue.filter("formatDate",formatDate)
    }
}